/**
*	Header: events.h
*	
*	This header defines the event handler, which will handle combat and game message passing
*	and display.
*	
*/

#pragma once

#include <fstream>
#include <unordered_set>

class Actor;

struct Notification {

};

enum EventType {
	GENERIC,
	COMBAT
};

struct Event {
	Event();

	static const EventType type = GENERIC;
	void (*target) (Event);
	Actor* source;
};

Event::Event() {
	target = nullptr;
}

struct CombatEvent: public Event {
	CombatEvent();
	CombatEvent(Actor* src, void (*tgt) (Event), const unsigned int damage = 0);
	
	unsigned int damagePoints;
	static const EventType type = COMBAT;
};

CombatEvent::CombatEvent() {
}

CombatEvent::CombatEvent(Actor* src, void (*tgt) (Event), const unsigned int damage) {
	source = src;
	target = tgt;
	damagePoints = damage;
}

class EventHandler {
public:
	void subscribe(void (*onNotify) (Notification));
	void call(const Event& evt);
private:
	void notifyAll(const Notification& evt);
	std::unordered_set <void (*) (Notification)> subscribers;
};

void EventHandler::subscribe(void (*onNotify) (Notification)) {
	subscribers.insert(onNotify);
}

void EventHandler::call(const Event& evt) {
	evt.target(evt);
}

void EventHandler::notifyAll(const Notification& evt) {
	for ( auto it = subscribers.cbegin(); it != subscribers.cend(); ++it ) (*it)(evt);
}